#!/bin/bash
# version: V1.0.0 -- 202207061634

t=$(date +%m%d)
longtime=$(date +%Y%m%d%H%M)
a="初始化mysql"
a1="重新初始化"
a2="初始化mysql(非root)"
b="设置远程访问"
c="重置mysql"
d="设置开机启动"
e="导入数据脚本"
z="取消"


function f_select() {
	PS3=-'请输入对应的数字选择要执行的操作！'
	select slt in $a $a1 $b $c $d $e $z; do
		case $slt in
		"$a")
		    if [ $UID -ne 0 ];then
                echo "Non root user. Please run as root."
                exit 0
            fi
			source mysql_reset.sh
			reset
			clean_file

			source mysql_init.sh
			full_install
			if [ $? -ne 0 ]; then
                echo -e "\033[31m mysql_init failed: so exit insert\033[0m"
                exit 1
            fi
			set_access_passwd
			./init_auto_start.sh
			break
			;;
		"$a1")
			if [ $UID -ne 0 ];then
                echo "Non root user. Please run as root."
                exit 0
            fi
            source mysql_reset.sh
			reset

            source mysql_init.sh
            re_init
            if [ $? -ne 0 ]; then
                echo -e "\033[31m mysql_init failed: so exit insert\033[0m"
                exit 1
            fi
			set_access_passwd
            ./init_auto_start.sh
            break
            ;;
		"$a2")
			source mysql_reset.sh
			reset
			clean_file

            source mysql_init.sh
            re_init
			set_access_passwd
			break
			;;
		"$b")
            source mysql_init.sh
            set_access_passwd
			break
			;;
		"$c")
			source mysql_reset.sh
			reset
			clean_file

			break
			;;
        "$d")
            ./init_auto_start.sh
            break
            ;;
        "$e")
            ./mysql_source.sh
            break
            ;;
		"$z")
			echo 'bay,bay!!'
			exit
			;;
		*)
			echo "输入错误，请重新选择！"
			break
			;;
		esac
	done
	f_select
}

f_select
